package com.wdb007.venus.wss.utils;

import java.io.IOException;
import java.security.MessageDigest;

public class MD5Util {

	/**
	 * 生成md5
	 * 
	 * @param message
	 * @return
	 */
	public static String getMD5(String message) {
		String md5str = "";
		try {
			// 1 创建一个提供信息摘要算法的对象，初始化为md5算法对象
			MessageDigest md = MessageDigest.getInstance("MD5");

			// 2 将消息变成byte数组
			byte[] input = message.getBytes();

			// 3 计算后获得字节数组,这就是那128位了
			byte[] buff = md.digest(input);
			// 4 把数组每一字节（一个字节占八位）换成16进制连成md5字符串
			md5str = bytesToHex(buff);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return md5str;
	}

	/**
	 * 二进制转十六进制
	 * 
	 * @param bytes
	 * @return
	 */
	public static String bytesToHex(byte[] bytes) {
		StringBuffer md5str = new StringBuffer();
		// 把数组每一字节换成16进制连成md5字符串
		int digital;
		for (int i = 0; i < bytes.length; i++) {
			digital = bytes[i];

			if (digital < 0) {
				digital += 256;
			}
			if (digital < 16) {
				md5str.append("0");
			}
			md5str.append(Integer.toHexString(digital));
		}
		return md5str.toString();
	}
	
	
	public static void main(String[] args) throws IOException {
		String time = System.currentTimeMillis() / 1000 + "";
		String str = "uYhomDi72i1w1LV6eG53vfPZ0Jm6FOHYBqS5fxyzVyYMiAY49lvA69LVgMs2X1hE9hJAPLan9FfsCqIfCtfktdfuuSxzjvzn3Tnf0nqhROU2naQ76YoPhMVnzTdvBv9b1AMfPiDKwAbfb6Of4CNrcfzAn9euEz8NkmvkuTqV7JrbmwkiLNty3BT0cdkIcy1dlrUOHX8YEUYewuds6RROpevcTg5hBDHXPXtOeZJuxvqnV7SMN4aAg1tHiY1OSdwvfqVW9tdWZbJUXt5JtDi4SvXcVmICZJsqOLI8IC97LrpZuV78063EZmftjZstFYCJZObH9z0fScSCAdZIJBS57BYmUz39utTXrHXNEtmVzk181glZKQGxWYg29tP7k0AAPL1o3TBmOKEBHzZ1CRhgcjMevQaCNs1LcuwwkkSWxIfB3WubG7Pr9NTzFcFi2meZJvti1KWmREXtJqR6VqZY19lOIN2uLgoO6kP7AYlpfC4V0Mmv2UDBlRMbVNFT3D3xiSVCjlGCsga9JrmKQnxvg09uLefav9GLnSghviEfC5MqSU2MCVwUadpwpzTXbYGsmWOGkQNIOhJamj44x7ROgp89WsrowJJxrz6T1nXO5R7rO1IkaFMMS3t7DRlh9R09DY9N3ufFyYOGoRfPcRXQWUzYx0fTCghggJ2nuqcJtLLXaoMw0tzGSz8fpF64NqV98EG2rSMeiuJiUzrwWT0vskivIJT8qdpjKo0YBZExeusf4fMzRcqx14Yj0iYuV2LP9TB3sxRBCBqvUBKcdkc0xuJVCW3IxAh5YpyH45dHtLogoxQlP7tkBc7sivHkJvUN4gYULCiluqc2ruppDh3Cl419b1dPdn5DTKdbfbhKU7GiqNPXa4WM4P8wFbzr2ccYNzAiwBtV0czoHIytcgzck98ytdPe9h2WP1Npmk44KESwJkpFlxPreW7G8NLliNsnExWXQ3xUEBHfMZZbIcilkewAXNEIGIcS1Z6urejUVDq79ZJbtDSouYu5FBr7pOWw";
		System.out.println("time:" + time);
		String transStr = getMD5(str + time);
		System.out.println(transStr);
	}
}
